package util;

import java.util.List;

/**
 * @author yuank
 * @version 1.0.0
 * @date 2024/12/20 17:25:41
 */
public class ThreadLocalUse {
    private static final ThreadLocal<User> userThreadLocal = new ThreadLocal<>();
    private static final ThreadLocal<String> requestIdThreadLocal = new ThreadLocal<>();
    private static final ThreadLocal<List<String>> permissionsThreadLocal = new ThreadLocal<>();

    public static void setUser(User user) {
        userThreadLocal.set(user);
    }

    public static User getUser() {
        return userThreadLocal.get();
    }

    public static void setRequestId(String requestId) {
        requestIdThreadLocal.set(requestId);
    }

    public static String getRequestId() {
        return requestIdThreadLocal.get();
    }

    public static void setPermissions(List<String> permissions) {
        permissionsThreadLocal.set(permissions);
    }

    public static List<String> getPermissions() {
        return permissionsThreadLocal.get();
    }

    public static void clear() {
        userThreadLocal.remove();
        requestIdThreadLocal.remove();
        permissionsThreadLocal.remove();
    }
}
class User{
    private String username;
    private String password;
}